package com.ruoyi.qiushi.service.system.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.qiushi.domain.system.QiushiInstitution;
import com.ruoyi.qiushi.mapper.system.QiushiInstitutionMapper;
import com.ruoyi.qiushi.service.system.IQiushiInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 机构管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-28
 */
@Service
public class QiushiInstitutionServiceImpl implements IQiushiInstitutionService {
    @Autowired
    private QiushiInstitutionMapper qiushiInstitutionMapper;

    /**
     * 查询机构管理
     *
     * @param id 机构管理主键
     * @return 机构管理
     */
    @Override
    public QiushiInstitution selectQiushiInstitutionById(Long id) {
        return qiushiInstitutionMapper.selectQiushiInstitutionById(id);
    }

    /**
     * 查询机构管理列表
     *
     * @param qiushiInstitution 机构管理
     * @return 机构管理
     */
    @Override
    public List<QiushiInstitution> selectQiushiInstitutionList(QiushiInstitution qiushiInstitution) {
        return qiushiInstitutionMapper.selectQiushiInstitutionList(qiushiInstitution);
    }

    /**
     * 新增机构管理
     *
     * @param qiushiInstitution 机构管理
     * @return 结果
     */
    @Override
    public int insertQiushiInstitution(QiushiInstitution qiushiInstitution) {
        if (qiushiInstitution.getParentId() != null) {
            QiushiInstitution temp = selectQiushiInstitutionById(qiushiInstitution.getParentId());
            qiushiInstitution.setLevelFlag(temp.getLevelFlag() + 1);
        }

        qiushiInstitution.setCreateTime(DateUtils.getNowDate());
        return qiushiInstitutionMapper.insertQiushiInstitution(qiushiInstitution);
    }

    /**
     * 修改机构管理
     *
     * @param qiushiInstitution 机构管理
     * @return 结果
     */
    @Override
    public int updateQiushiInstitution(QiushiInstitution qiushiInstitution) {
        qiushiInstitution.setUpdateTime(DateUtils.getNowDate());
        return qiushiInstitutionMapper.updateQiushiInstitution(qiushiInstitution);
    }

    /**
     * 删除机构管理信息
     *
     * @param id 机构管理主键
     * @return 结果
     */
    @Override
    public int deleteQiushiInstitutionById(Long id) {
        return qiushiInstitutionMapper.deleteQiushiInstitutionById(id);
    }
}
